import Mock from 'mockjs'
import { param2Obj } from '../utils/workUtlis/urlUtils'

var list = []
for (let i = 0; i < 100; i++) {
    list.push({
        id: Mock.mock('@guid()'),
        username: Mock.mock('@cname'),//患者姓名
        // address: Mock.mock('@county(true)'),
        type: Mock.mock('@natural(1, 5)'),//vip等级
        sextype: Mock.mock('@natural(1, 2)'),//性别
        age: Mock.mock('@natural(1, 100)'),//年龄
        atatetype: Mock.mock('@natural(1, 3)'),//接诊状态
        doctorname: Mock.mock('@cname'),//医生姓名
        creatTime: Mock.mock('@datetime()'),//时间
        phone: Mock.mock(/^[1][3-9][0-9]{9}$/), //手机号码

    })

}
//后台接口逻辑
export default {
    getwork: (config) => {
        
        var { valname, state, page, pageSize, timeinitiation, timeend } = param2Obj(config.url)

        var res = list.filter(item => item.username.indexOf(valname) != -1)//过滤输入搜索的结果，搜索框
        var timeres
        if (timeinitiation != 0 && timeend != 0 ) {
            // var date1 = new Date(list[1].creatTime);//后台数据转化为时间戳
            var date2 = new Date(timeinitiation);//后台数据转化为时间戳
            var date3 = new Date(timeend);//后台数据转化为时间戳
            // var time1 = date1.getTime();

            var time2 = date2.getTime();
            var time3 = date3.getTime();
            // console.log(time2, time3);
            console.log(res);
            timeres = res.filter(item =>

                new Date(item.creatTime).getTime() >= time2 && new Date(item.creatTime).getTime() <= time3
            )
            console.log(timeres);
            res = timeres
        }

        var res1
        if (state * 1 != 0) {
            res1 = res.filter(item => item.atatetype == state)//过滤输入搜索的结果，状态选择框
            res = res1
        }
        var reslimt = res.filter((item, index) => {
            return (page - 1) * pageSize <= index && index < page * pageSize//分页
        })

        return {
            code: 200,
            msg: '请求成功',
            data: reslimt,
            total: res.length
        }
    }
}